package com.edu.servlet;

import java.io.IOException;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.edu.service.AdminService;
import com.edu.service.impl.AdminServiceImpl;

@WebServlet("/login.do")
public class AdminLoginServlet extends HttpServlet {
	private AdminService admins=new AdminServiceImpl();
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String adminName=req.getParameter("admin");
		String password=req.getParameter("password");
		HttpSession session=req.getSession();
		Map<String, Object> map =admins.login(adminName, password);
		if(map.get("loginAdmin")!=null) {
			session.setAttribute("login", map);
			resp.sendRedirect("Book.do");
		}else {
			session.setAttribute("msg", map.get("msg"));
			req.getRequestDispatcher("login.jsp").forward(req, resp);
		}
	}
}
